package cn.binux;

import cn.binux.utils.JedisClient;
import cn.binux.utils.JedisProperties;
import cn.binux.utils.impl.JedisClientSingle;
import redis.clients.jedis.JedisPool;
import redis.clients.jedis.JedisPoolConfig;

import org.mybatis.spring.annotation.MapperScan;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.transaction.annotation.EnableTransactionManagement;

@EnableHystrix
@Configuration
@SpringBootApplication
@EnableDiscoveryClient
//@EnableApolloConfig
@EnableTransactionManagement
@MapperScan(basePackages = "cn.binux.mapper")
public class XbinStoreServiceCartApplication {

	public static void main(String[] args) {
		SpringApplication.run(XbinStoreServiceCartApplication.class, args);
	}

	@Bean
	@Primary
	public JedisPool redisPoolFactory() {
		JedisPoolConfig jedisPoolConfig = new JedisPoolConfig();
		JedisProperties jedisProperties = getJedisProperties();
		JedisPool jedisPool = new JedisPool(jedisPoolConfig, jedisProperties.getHost(), jedisProperties.getPort(),
				jedisProperties.getTimeout(), jedisProperties.getPassword());
		return jedisPool;
	}

	@Bean
	@Primary
	@ConfigurationProperties(prefix="spring.redis")
	public JedisProperties getJedisProperties(){
		JedisProperties jedisProperties = new JedisProperties();
		return jedisProperties;
	}
	@Bean
	@Primary
	public JedisClient jedisClient() {
		return new JedisClientSingle();
	}
}
